import java.util.Random;

/**
 * @author: gao
 * @create-date: 2025/3/8 14:42
 */

public class Sort {
    public void DisOrder(int[] array) {
        Random ran = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = ran.nextInt(100);
        }
    }

    public void SelectSort(int[] array) {
        int left = 0, right = array.length - 1;
        while (left < right) {
            int MinIndex = left, MaxIndex = left;
            for (int i = left + 1; i <= right; i++) {
                if (array[i] < array[MinIndex]) {
                    MinIndex = i;
                }
                if (array[i] > array[MaxIndex]) {
                    MaxIndex = i;
                }
            }
            swap(array, MinIndex, left);
            if (left == MaxIndex) {
                MaxIndex = MinIndex;
            }
            swap(array, MaxIndex, right);
            left++;
            right--;
        }
    }

    private void swap(int[] array, int i, int j) {
        int tmp = array[i];
        array[i] = array[j];
        array[j] = tmp;
    }
}